from collections import defaultdict

n, m = map(int, input().split())
board = [list(map(int, input().split())) for _ in range(n)]
land_ptr = 0  # 指向岛屿的指针
near_land = defaultdict(set)


def dfs(i, j):
    r = 0
    if i < 0 or i >= n: return 0
    if j < 0 or j >= m: return 0
    if board[i][j] != 1:
        near_land[(i, j)].add(land_ptr)
        return 0
    board[i][j] = 0
    r += dfs(i + 1, j)
    r += dfs(i - 1, j)
    r += dfs(i, j + 1)
    r += dfs(i, j - 1)
    return r + 1


max_area = 0

land_areas = []

for x in range(n):
    for y in range(m):
        if board[x][y] == 1:
            land_areas.append(dfs(x, y))
            land_ptr += 1
result = 0
for key, values in near_land.items():
    max_value = 0
    if len(values) > 1:
        max_value += 1
    for value in values:
        max_value += land_areas[value]
    result = max(result, max_value)

print(max(result, 1))
